how to apply rank function for duplicate